<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>购物车</title>
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, width=device-width">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-touch-fullscreen" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no">
		<meta name="format-detection" content="address=no">
		<link rel="stylesheet" type="text/css" href="css/common.css">
		<link rel="stylesheet" type="text/css" href="css/index.css">
		<link rel="stylesheet" type="text/css" href="css/mui.min.css"/>
		<link rel="stylesheet" href="css/reset.css">
		
		<script type="text/javascript" src="js/jquery.min.js"></script>
	    <script type="text/javascript" src="js/iscroll.js"></script>
		<script type="text/javascript" src="js/jquery.flexslider-min.js"></script>
		<script src="js/hmt.js" type="text/javascript"></script>
		<script type="text/javascript" src="js/index.js"></script>
		<script src="js/swiper.min.js" type="text/javascript" ></script>
		
		<script type="text/javascript" src="http://yanyubao.tseo.cn/Tpl/static/jquery.tmpl.js"></script>
		<script type="text/javascript" src="js/abot.js"></script>
		<script type="text/javascript" src="http://yanyubao.tseo.cn/api/shopapp.js"></script>
		<script type="text/javascript" src="js/abot.function.js"></script>
		
	</head>
	<body>
		<!--header star-->
		<header class="hasManyCity hasManyCitytwo" id="header">
			<a href="index.html" class="fl fanhui">
			<i class="iconfont">&#xe6d4;</i>
			</a>
			<div class="header-tit">
				购物车
			</div>	
			
			    <a href="#" class="fr shanchu">
				<!-- <i class="iconfont icon-lajixiang fr"></i> -->
			</a> 
		</header>
	    <!--header end-->
	    <div id="container">		
			<div id="main">	
			    <div class="warp warptwo clearfloat">
			    	<div class="shopcar clearfloat" id="cart_list">
			    	
			    	<script id="cart_item" type="text/x-jquery-tmpl">
			    		<div class="list clearfloat fl">
			    			<div class="xuan clearfloat fl">
			    				<div class="radio" > 
								    <label>
								        <input type="checkbox" name="sex" value="" />
								        <div class="option"></div>
								    </label>
								</div>
			    			</div>
			    			<a href="#">
				    			<div id="cart" class="tu clearfloat fl">
				    				<span></span>
				    				<img src="${picture}"/>
				    			</div>
				    			<div class="right clearfloat fl">
				    				<p class="tit over">${name}</p>
				    				<p class="fu-tit over">颜色：金色  内存：1287G</p>
				    				<p class="jifen over">${price}元</p>
				    				<div class="bottom clearfloat">
				    					<div class="zuo clearfloat fl">
				    						<ul>
				    							<li><img class="minus" src="img/jian.png"/></li>
				    							<li class="count">1</li>
				    							<li><img class="plus" src="img/jia.png"/></li>
				    						</ul>
				    					</div>
				    					<i class="iconfont fr cart" onclick="del_cart(${productid})">&#xe6e2;</i>
				    				</div>
				    			</div>
			    			</a>
			    			</div>			
						</script>	
			    			
			    					    	
			    	</div>
			    </div>
			</div>
		</div>
	
	
	
	    
	    <!--settlement star-->
	    <div class="settlement clearfloat">
	    	<div class="zuo clearfloat fl box-s">
	    		合计：<span id="heji">￥0</span>
	    	</div>
	    	<a class="fl db" id="jiesuan">
	    		立即结算
	    	</a>
	    </div>
	    <!--settlement end-->	    
		
	</body>
	
<script type="text/javascript">

var loginItem = get_login_info();//获取登录信息 

var userid = loginItem.userid;

var checkstr = loginItem.checkstr;
//删除购物车
 function del_cart(productid){
	/*  alert(productid) */
	 
	var function_cart_del_name = "cart_del";
	
	var request_cart_del_data = {'userid':userid, 'checkstr':checkstr ,'productid':productid};
	
	ajax_request_server(function_cart_del_name,request_cart_del_data,cart_del_callback);
	
};

function cart_del_callback(res){
	
	
	  if(res.code == 1){
		
		  alert(res.msg);
		  
		window.location.reload();
				
	};
	
	 	alert(res.msg);	
	
};



 function product_detail_callback(res){
	
	$("#cart_item").tmpl(res.data).appendTo("#cart_list");
	
}; 

function cart_list_callback(res){
	
	var arr_cart = res.data;
	
	console.log(arr_cart);//购物车里面的商品
	
	 var count = "";
	
	var zongprice = 0;
	
	var pro_arr = new Array() ;
	
	 for(var i = 0;i < arr_cart.length;i++){
		 
		 productid = arr_cart[i]['productid'];//商品id 
		 
		 pro_arr[i] =productid
		 
		 console.log(pro_arr);
		 
		 amount = arr_cart[i]['amount'];//购买的数量
			
			var function_name = "product_detail";
			
			var request_data = {'userid':userid, 'checkstr':checkstr,'productid':productid };
			
					var a = arr_cart[i]['price'];
					
		 			zongprice += parseInt(a);
			
			 
			ajax_request_server(function_name, request_data, product_detail_callback);//商品详情
				
	}
	 
	$("#heji").text("￥"+zongprice);
	 
	sessionStorage["zong"] = zongprice;
	
	
	 var num = " ";
	  for(var i = 0;count.length;i++){
		 
		 num += count[i]
		 
		$(".count").val(num);
		 
	 } 
	 $("#jiesuan").click(function(){
		 
		 sessionStorage["product_id"] = pro_arr;//存储productid的数组
		
		 //console.log(pro_arr);
		 
		 window.location.href="indiana-shu.html";
	 })
	 
	
	
};

$(function(){
	
	if(!is_user_login()){
		window.location.href = 'login.html';
		return;
		
	};
	
	//购物车列表
	
	var function_name = "cart_list";
	
	var loginItem = get_login_info();//获取登录信息 

	var userid = loginItem.userid;
	
	var checkstr = loginItem.checkstr;
	
	var request_data = {'userid':userid, 'checkstr':checkstr };
		
	 ajax_request_server(function_name,request_data, cart_list_callback);
	

	
		
});


</script>
	
</html>


	    
	    
